package com.wuyou.mid;


/**
 * 1806. 还原排列的最少操作步数
 */
public class ReinitializePermutation {

    public static void main(String[] args) {
        int n = 24;

        System.out.println(solution_1(n));
    }

    // 57.89%
    public static int solution_1(int n) {
        int[] perm = new int[n];
        for (int i = 0; i < perm.length; i++) {
            perm[i] = i;
        }
        int countRes = 0;
        while (true) {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                if (i % 2 == 0) {
                    arr[i] = perm[i / 2];
                } else {
                    arr[i] = perm[n / 2 + (i - 1) / 2];
                }
            }
            perm = arr;
            countRes++;
            if (perm[1] == 1) break;
        }
        return countRes;
    }
}
